﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;


namespace BCNPCObject.EXCEL
{
    public class cls_GCS_CHISO_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private GCS_CHISO info;

        #endregion

        #region   Constructor

        public cls_GCS_CHISO_Controller()
        {
            info = new GCS_CHISO();
        }
        public cls_GCS_CHISO_Controller(GCS_CHISO Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public GCS_CHISO pInfor
        {
            get { return info; }
            set { info = value; }
        }
        #endregion

        #region Methods
        public bool insert_GCS_CHISO(ref Int64 id_chiso,ref string maloi)
        {
            long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_GCS_CHISO.NEXTVAL from dual");
            if (_ID == -1) return false;
            try
            {
                info.ID_CHISO = Convert.ToInt64(_ID);
                GCS_CHISO objGCS_CHISO = new GCS_CHISO()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    ID_CHISO = info.ID_CHISO,
                    ID_BCS = info.ID_BCS,
                    MA_DDO = info.MA_DDO,
                    BCS = info.BCS,
                    HS_NHAN = info.HS_NHAN,
                    MA_CTO = info.MA_CTO,
                    SO_CTO = info.SO_CTO,
                    KY = info.KY,
                    THANG = info.THANG,
                    NAM = info.NAM,
                    CHISO_CU = info.CHISO_CU,
                    CHISO_MOI = info.CHISO_MOI,
                    SAN_LUONG = info.SAN_LUONG,
                    SLUONG_TTIEP = info.SLUONG_TTIEP,
                    SLUONG_TRPHU = info.SLUONG_TRPHU,
                    LOAI_CHISO = info.LOAI_CHISO,
                    MA_TTCTO = info.MA_TTCTO,
                    NGAY_DKY = info.NGAY_DKY,
                    NGAY_CKY = info.NGAY_CKY,
                    SLUONG_1 = info.SLUONG_1,
                    SLUONG_2 = info.SLUONG_2,
                    SLUONG_3 = info.SLUONG_3,
                    MA_KHANG = info.MA_KHANG,
                    MA_CNANG = info.MA_CNANG,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA
                };
                CMIS2.DB.GCS_CHISO.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                id_chiso = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_GCS_CHISO(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.GCS_CHISO
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.ID_CHISO == Convert.ToInt64(dt.Rows[i]["ID_CHISO"]))
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.GCS_CHISO.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion
    }
}
